<?php

namespace App\Models;
/**
 * Class Article
 * @package App\Models
 */
class Article extends BaseModel
{
    /**
     * 字段
     * @var array
     */
    protected $fillable = [
        'id',
        'title',
        'flag'
    ];

    const FLAGS = [
        '1' => '推荐',
        '2' => '有图',
        '3' => '最新',
        '4' => '热门'
    ];

    const FLAG_KEY = 'AF';

    public function getFlagTextAttribute($key)
    {
        $texts = [];
        $values = \App\Facade\Code::get(self::FLAG_KEY);

        foreach ($values as $key => $value) {
            if ($this->flag & (1 << ($key - 1))) {
                $texts[] = $value;
            }
        }
        return implode('、', $texts);
    }
}
